package com.sky.controller.user;

import com.sky.controller.BaseController;
import com.sky.entity.CategoryEntity;
import com.sky.enumeration.CategoryTypeEnum;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.utils.TransformUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("UserCategoryController")
@RequestMapping("/user/category")
@Slf4j
@Api(tags = "分类相关")
public class CategoryController extends BaseController {

    @Autowired
    private CategoryService categoryService;


    @GetMapping("/list")
    @ApiOperation("获取分类列表")
    @CacheEvict(cacheNames = "ac", allEntries = true)
    public Result list(@RequestParam(required = false) String type) {
        CategoryTypeEnum categoryTypeEnum = TransformUtils.transformEnum(type, CategoryTypeEnum.class);
        List<CategoryEntity> list = categoryService.getByType(categoryTypeEnum);
        return Result.success(list);
    }
}
